package cn.gan.loveofsoul.commons.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @Description:
 * @Author: ganwh
 * @Since: 2023/10/25 10:34
 */
public class FileUtil {
    // 文件后缀获取
    public static String getExtensionName(String fileName) {
        if (fileName == null || fileName.length() == 0) {
            return null;
        }
        int index = fileName.lastIndexOf(".");
        if (index < 0 || index > fileName.length() - 1) {
            return null;
        }
        return fileName.substring(index + 1);
    }
    // 获取文件大小KB
    public static String getFileSize(long size, int round) {
        BigDecimal decimal = new BigDecimal(size / 1024);
        return decimal.setScale(round, RoundingMode.HALF_UP).doubleValue() + "KB";
    }
}
